package com.example.mymap_beta;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;


public class MyIconOverLay extends Overlay{

	private int sourceImage = 0;
	private GeoPoint geoPoint =null;
	private static Context context;
	
	public MyIconOverLay(int source, GeoPoint geoP)
	{
		this.sourceImage = source;
		this.geoPoint 	= geoP;
	}
	
	public MyIconOverLay(int source) {
		this.sourceImage = source;
		
	}

	@Override
	public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
		// TODO Auto-generated method stub
		super.draw(canvas,mapView,shadow);
		
		// translate the GeoPoint to screen pixels
		Point screenPts = new Point();
		if(geoPoint != null && sourceImage != 0)
		{
			mapView.getProjection().toPixels(geoPoint, screenPts);
			
			// add
			Bitmap bmp = BitmapFactory.decodeResource(context.getResources(),sourceImage);
			canvas.drawBitmap(bmp,screenPts.x - bmp.getWidth()/2, screenPts.y - bmp.getHeight(), null);
			
			
			
			return true;
		}
		
		else return false;
		
		
		
	}

	public static void setContext(Context context) {
		MyIconOverLay.context = context;
	}

	public int getSourceImage() {
		return sourceImage;
	}

	public void setSourceImage(int sourceImage) {
		this.sourceImage = sourceImage;
	}

	public GeoPoint getGeoPoint() {
		return geoPoint;
	}

	public void setGeoPoint(GeoPoint geoPoint) {
		this.geoPoint = geoPoint;
	}
	
	
	
	
	
}
